﻿#!/usr/bin/env python

import sys
sys.path.append("/cygdrive/d/Eclipse/ScriptsCode/python/Hive")
from hive_service import ThriftHive
from hive_service.ttypes import HiveServerException
from thrift import Thrift
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol

def hiveExe(sql):
	try:
		transport = TSocket.TSocket('10.195.84.12', 14000)
		transport = TTransport.TBufferedTransport(transport)
		protocol = TBinaryProtocol.TBinaryProtocol(transport)
		client = ThriftHive.Client(protocol)
		transport.open()

		client.execute(sql)

		print "The return value is : "
		print client.fetchAll()
		print "............"
		transport.close()
	except Thrift.TException, tx:
		print '%s' % (tx.message)

if __name__ == '__main__':
	hiveExe("select * from imsg_push_log_tmp limit 3")
